package com.hzj.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {

    @Bean //创建FanoutExchange类型的交换机
    public FanoutExchange saveOrderInfoExchange() {
        return new FanoutExchange("Fanout.Exchange.saveOrderInfo"/*交换机名称*/, true, false);
    }

    @Bean //创建FanoutExchange类型的交换机
    public FanoutExchange updateOrderByHosRecordIdExchange() {
        return new FanoutExchange("Fanout.Exchange.updateOrderByHosRecordId"/*交换机名称*/, true, false);
    }

    @Bean //创建FanoutExchange类型的交换机
    public FanoutExchange updateScheduleByIdExchange() {
        return new FanoutExchange("Fanout.Exchange.updateScheduleById"/*交换机名称*/, true, false);
    }

    //声明三个队列
    @Bean
    public Queue saveOrderInfoQueue() {
        return new Queue("Fanout.queue.saveOrderInfoQueue", true);
    }

    @Bean
    public Queue updateOrderByHosRecordIdQueue() {
        return new Queue("Fanout.queue.updateOrderByHosRecordIdQueue", true);
    }

    @Bean
    public Queue updateScheduleByIdQueue() {
        return new Queue("Fanout.queue.updateScheduleByIdQueue", true);
    }


    @Bean //
    public Binding saveOrderInfoBingdingBinding() {
        return BindingBuilder.bind(saveOrderInfoQueue()/*参数为队列*/).to(saveOrderInfoExchange()/*参数为交换机*/);//Fanout交换机没有routingKey值
    }

    @Bean //
    public Binding updateOrderByHosRecordIdBinding() {
        return BindingBuilder.bind(updateOrderByHosRecordIdQueue()/*参数为队列*/).to(updateOrderByHosRecordIdExchange()/*参数为交换机*/);//Fanout交换机没有routingKey值
    }

    @Bean //
    public Binding updateScheduleByIdBinding() {
        return BindingBuilder.bind(updateScheduleByIdQueue()/*参数为队列*/).to(updateScheduleByIdExchange()/*参数为交换机*/);//Fanout交换机没有routingKey值
    }



//    @Bean//序列化配置
//    public MessageConverter messageConverter(){
//        return new Jackson2JsonMessageConverter();
//    }

}
